export default {
	data() {
		return {
			// msg: '',
			fatherIndex: 0, //一级菜单默认index
			/*菜单列表*/
			items: [],
			portalConfigList: [], //门户列信息
      validate: {}, //验证对象
			modelShow: false,
			token: this.get("token"), //token
			userRole: this.get("userRole"), //角色信息
			userInfo: this.get("userInfo"), //用户信息
		}
	},
	updated:function(){
		if(this.getParamValue("fatherIndex")){
			this.fatherIndex=this.getParamValue("fatherIndex");
		}
	},
	created() { //调用方法

		let that = this;

		that.findMenuBy();
/*		let now = new Date(),
			hour = now.getHours()
		if(hour < 6) {
			that.msg = "凌晨好"
		} else if(hour < 9) {
			that.msg = "早上好"
		} else if(hour < 12) {
			that.msg = "上午好"
		} else if(hour < 14) {
			that.msg = "中午好"
		} else if(hour < 17) {
			that.msg = "下午好"
		} else if(hour < 19) {
			that.msg = "傍晚好"
		} else if(hour < 22) {
			that.msg = "晚上好"
		} else {
			that.msg = "夜里好"
		}*/
		//初始化友情连接信息
		that.$post(
				that.urls.getAllPortalConfigList, {
					"type": 1
				}
			)
			.then(function(res) {
				if(res.success) {
					that.portalConfigList = res.data;
				}
			})
	},
	mounted() {
    let that = this;
    //校验密码
    $.validator.addMethod("checkPassword", function(value, element, params) {
      let re = /^[0-9a-zA-Z]{6,16}$/;
      let flg = value.match(re);
      return this.optional(element) || flg;
    }, "密码只能输入6-16个数字或字母!");

    //校验源密码
    $.validator.addMethod("checkOrdPassword", function(value, element, params) {
      let flg = value == that.get("userInfo").userPassword;
      return this.optional(element) || flg;
    }, "原密码输入错误!");

    //加载表单验证
    that.validate = $("#updatePasswordForm").validate({
      ignore: [],
      rules: {
        ordPassword: { //源密码
          required: true,
          checkOrdPassword: true,
          checkPassword: true
        },
        userPassword: { // 新密码
          required: true,
          checkPassword: true
        },
        secondaryUserPassword: { // 二次密码
          required: true,
          equalTo: "#userPassword"
        }
      },
      messages: {
        ordPassword: { //源密码
          required: "请输入原密码"
        },
        userPassword: { // 新密码
          required: "请输入新密码！"
        },
        secondaryUserPassword: { // 二次密码
          required: "请输入确认密码！",
          equalTo: "确认密码与新密码不同！"
        }
      },
//			errorElement: "em",
//			errorPlacement: function(error, element) {
//				error.appendTo(element.parents(".error-box").children(".error-msg"));
//			}
    });

    if(that.userInfo.headPortrait != ' ' && that.userInfo.headPortrait){
      $('#headImg').attr('src', that.urls.baseUrl + that.userInfo.headPortrait)
      $('#headImgs').attr('src', that.urls.baseUrl + that.userInfo.headPortrait)

    }
  },
	methods: { //写函数方法
		//用户下拉信息鼠标事件
		showUl: function() {
			$(".wkp-right>div>ul").css("display", "block");
		},
		leaveDiv: function() {
			$(".wkp-right>div>ul").css("display", "none");
		},
		/*		showToggle: function(ind, item) {
					this.fatherIndex = ind;
					this.$router.push({
						path: item.path
					})

				},*/
		openModal: function() {
      $("input[type=reset]").trigger("click");
      this.validate.resetForm();
      this.modelShow = true;
		},
		closeModel: function() {
			this.modelShow = false;
		},
		//角色菜单查询
		findMenuBy: function() {
			let that = this;
			that.$post(
					that.urls.findMenuByRole, {
						roleId: that.userRole != null ? that.userRole.id : null,
						Authorization: that.token
					}
				)
				.then(function(res) {
					if(res.success) {
						that.items = res.data;
					} else {
						layer.alert(res.message);
					}
				})
				.catch(function(err) {
					if(err.response) {
						console.log(err.response)
						//控制台打印错误返回的内容
						layer.msg('失败！', {
							time: 3000, //3s后自动关闭
						});
					}
				})
		},

		/*菜单切换*/
		showToggle: function(ind, item) {
			this.fatherIndex = ind;
			this.$router.push({
				path: item.url+"?fatherIndex="+ind
			})

		},
		clickChild: function(inds, subItem) {
			this.changindex = inds;
			this.$router.push({
				path: subItem.path
			})
		},
    //确定修改
    defineUpdate: function() {
      let that = this;
      let flg = that.validate.form();
      if(flg) {
        let dataObj = {};
        dataObj["id"] = this.get("userInfo").id;
        dataObj["userPassword"] = $("input[name='userPassword']").val();
        that.$post(
          that.urls.editUser,
          dataObj
        )
          .then(function(res) {
            if(res.success) {
              that.set("token", null);//token
              that.set("userRole", null);//角色信息
              that.set("userInfo", null);//用户信息
              layer.msg("修改成功！", {
                time: 3000, //3s后自动关闭
              });
              that.$router.push({
                path: "login",
              })
            } else {
              layer.msg("修改失败！", {
                time: 3000, //3s后自动关闭
              });
            }
          })
      }
    },
		//退出登录
		logOut: function() {
			var that = this;
			that.clear(); //token
			that.$router.push({
				path: "login",
			})
			that.loginShow = true;
			that.userShow = false;
		},
	}
}
